#pragma once

namespace Next
{
	namespace Patterns
	{
		template <class T> class TSingleton
		{
		protected:
			TSingleton(){}
			virtual ~TSingleton(){}

		public:
			__declspec(noinline) static void Destroy()
			{
				if( pInstance )
				{
					delete pInstance;
					pInstance = NULL;
				}
			}

			__declspec(noinline) static T* Instance()
			{
				if( pInstance == NULL )
				{
					pInstance = new T;
				}

				return pInstance;
			}

		protected:
			static T* pInstance;
		};

		template <class T> T* TSingleton<T>::pInstance = NULL;
	}
}